<?
/*! \brief Switch on and do something in the event of application exceptions.
 * 
 */
class ErrorController extends Zend_Controller_Action {
	
	/*! \brief Default action
	 * 
	 * Switches on the exception held by Zend_Controller_Plugin_ErrorHandler. 
	 * Presently handles NO_CONTROLLER and NO_SERVICE, all others exceptions 
	 * return HTTP 500. All exceptions will populate error view with the 
	 * exception and request.
	 */
	public function errorAction()
	{
		$errors = $this->_getParam('error_handler');
		//echo $errors->exception;
		
		switch ($errors->type)
		{
			case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
	 		case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
	 			// 404 error -- controller or action not found
	 			$this->getResponse()->setHttpResponseCode(404);
				$this->view->message = 'No Service Found';
				break;
			default:
				// any other application error
				$this->getResponse()->setHttpResponseCode(500);
				$this->view->message = 'Application error';
				break;
		}
		
		$this->view->env       = $this->getInvokeArg('env');
		$this->view->exception = $errors->exception;
		$this->view->request   = $errors->request;
	}
}